package com.hippo.core.ui.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.hippo.core.R
import com.hippo.core.ui.theme.HippoTheme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SelectRegionDialog(onSure: () -> Unit) {

    val showDialog = remember { mutableStateOf(false) }

    BottomSheetScaffold(
        sheetContent = {
            Row(
                modifier = Modifier.padding(16.dp)
            ) {
                Text(stringResource(id = R.string.region_1))
                IconButton(onClick = { showDialog.value = false }) {
                    Icon(
                        imageVector = Icons.Filled.Close,
                        contentDescription = null
                    )
                }
            }
        },
        sheetPeekHeight = 0.dp,
        scaffoldState = rememberBottomSheetScaffoldState(),
        sheetShape = MaterialTheme.shapes.large,
        sheetContentColor = MaterialTheme.colorScheme.onSurface,
        sheetShadowElevation = 4.dp,
        sheetDragHandle = { BottomSheetDefaults.DragHandle() },
        sheetSwipeEnabled = true,
        content = {

            Column {
                ItemRegion(
                    text = stringResource(id = R.string.region_2),
                    checked = true,
                    onCheckedChange = null
                )
                ItemRegion(
                    text = stringResource(id = R.string.region_3),
                    checked = false,
                    onCheckedChange = null
                )
                ItemRegion(
                    text = stringResource(id = R.string.region_4),
                    checked = false,
                    onCheckedChange = null
                )
                ItemRegion(
                    text = stringResource(id = R.string.region_5),
                    checked = false,
                    onCheckedChange = null
                )
                ItemRegion(
                    text = stringResource(id = R.string.region_6),
                    checked = false,
                    onCheckedChange = null
                )
                ItemRegion(
                    text = stringResource(id = R.string.region_7),
                    checked = false,
                    onCheckedChange = null
                )


                ThemeButton(
                    modifier = Modifier.fillMaxWidth(),
                    text = stringResource(R.string.sure),
                    onClick = onSure
                )
            }

        }
    )
}


@Composable
private fun ItemRegion(
    text: String,
    checked: Boolean,
    onCheckedChange: ((Boolean) -> Unit)?,
) {
    Row(
        modifier = Modifier
            .padding(12.dp)
            .fillMaxWidth()
    ) {
        Text(text = text, modifier = Modifier.weight(1F))
        Checkbox(
            checked = checked,
            onCheckedChange = onCheckedChange
        )
    }

    HorizontalDivider(thickness = 0.5.dp)
}


@Preview(showBackground = true)
@Composable
private fun SelectRegionDialogPreview() {
    HippoTheme {
        SelectRegionDialog(){}
    }
}


